package com.github.byakkili.bim.core.support.util;

import cn.hutool.core.io.IoUtil;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;

import java.io.OutputStream;
import java.lang.management.ManagementFactory;
import java.lang.management.ThreadInfo;
import java.lang.management.ThreadMXBean;

/**
 * @author Guannian Li
 */
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class JvmUtils {

    public static void jstack(final OutputStream stream) {
        ThreadMXBean threadMxBean = ManagementFactory.getThreadMXBean();
        for (ThreadInfo threadInfo : threadMxBean.dumpAllThreads(true, true)) {
            IoUtil.write(stream, false, threadInfo.toString().getBytes());
        }
    }
}
